﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Oliving.Edge.Controllers.Oliving
{
    public class TestController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }





        #region  GetList 
        ///// <summary>
        ///// 获取所有数据
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //[AllowAnonymous]
        //[Route("/api/[controller]/GetList")]
        //public async Task<MessageModel<List<Sys_configDto>>> GetList()
        //{

        //    var data = new MessageModel<List<Sys_configDto>>();

        //    Parallel.For(0, 200, e =>
        //    {
        //        #region log

        //        //_logger.LogTrace("LogTrace");
        //        //_logger.LogDebug("LogDebug");
        //        //_logger.LogInformation("LogInformation");
        //        _logger.LogWarning("LogWarning = " + DateTime.Now);
        //        //_logger.LogError("LogError");


        //        //NlogHelper.saveNLog(new InvokeLogModel
        //        //{
        //        //    BeginTime = DateTime.Now,
        //        //    EndTime = DateTime.Now,
        //        //    InvokeResult = "InvokeResult" + DateTime.Now,
        //        //    InvokeUserName = "InvokeResult" + DateTime.Now,
        //        //    MethodName = "InvokeResult" + DateTime.Now,
        //        //    OutputJson = "InvokeResult" + DateTime.Now,
        //        //    RequestUrl = "InvokeResult" + DateTime.Now,
        //        //    InputJson = "InputJson############### = " + DateTime.Now.ToString()
        //        //}); ;

        //        #endregion
        //    });

        //    List<Sys_configDto> clist = await _sys_configServices.GetList();

        //    data.response = clist;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;
        //}




        #endregion


        #region  GetListCache 
        ///// <summary>
        ///// 获取所有数据 GetListCache
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //[AllowAnonymous]
        ////[Route("/api/[controller]/GetListCache")]
        //[CustomRoute(ApiVersions.V2, "GetListCache")]
        ////     /api/V2/SysConfig/GetListCache 
        ////[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]  // 禁止缓存
        ////[ResponseCache(Duration = 600)]           // 使用缓存
        ////示例显示来自Index()和Privacy()方法的响应被缓存30秒。
        ////    我们的想法是，这些方法生成的内容预计会保持不变。
        ////    GetValue()方法的响应不应该缓存，因为预期此方法的响应会从一个请求更改为另一个请求。
        ////    因此，禁用缓存由NoStore = true和Location = ResponseCacheLocation.None指示

        //public async Task<MessageModel<List<Sys_configDto>>> GetListCache()
        //{

        //    var data = new MessageModel<List<Sys_configDto>>();

        //    // 测试 AOP 缓存
        //    List<Sys_configDto> clist = await _sys_configServices.GetListCache();
        //    data.response = clist;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;
        //}



        ///// <summary>
        ///// 获取详情
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]

        //[AllowAnonymous]
        //[Route("/api/[controller]/GetCache")]
        //public async Task<MessageModel<Sys_configDto>> GetCache(int id)
        //{

        //    var data = new MessageModel<Sys_configDto>();

        //    // 测试 AOP 缓存
        //    Sys_configDto clist = await _sys_configServices.GetDtoCache(id);
        //    data.response = clist;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;
        //}



        #endregion


        #region  异常  

        //[HttpGet]
        //[AllowAnonymous]
        //[Route("/api/[controller]/GetEx")]
        //public async Task<MessageModel<bool>> GetEx()
        //{
        //    var data = new MessageModel<bool>();


        //    // 测试模拟异常，全局异常过滤器拦截
        //    var i = 0;
        //    var d = 3 / i;


        //    data.response = true;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;
        //}


        #endregion


        #region update

        //[HttpGet]
        ////[Authorize(Permissions.Name)]
        //[Route("/api/[controller]/TestUpdate")]
        //public async Task<MessageModel<bool>> TestUpdate()
        //{
        //    var data = new MessageModel<bool>();

        //    Sys_configDto dto = new Sys_configDto
        //    {
        //        C_ID = 3,
        //        C_Key = "C_Key_1",
        //        C_Name = "C_Name_1",
        //        C_Renark = "C_Renark_!",
        //        C_State = 2,
        //        C_Type = 3,
        //        C_Value = "C_Value_" + DateTime.Now.ToString()
        //    };

        //    // 测试 AOP 缓存
        //    bool clist = await _sys_configServices.UpdateDto(dto);
        //    data.response = clist;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;
        //}



        //[HttpPost]
        //[AllowAnonymous]
        //[Route("/api/[controller]/TestUpdateValidate")]
        //public async Task<MessageModel<bool>> TestUpdateValidate([FromBody]SysConfigDto dto)
        //{
        //    if (!ModelState.IsValid)
        //    {

        //    }

        //    var data = new MessageModel<bool>();


        //    return data;
        //}

        #endregion


        #region Other


        ///// <summary>
        ///// 获取所有数据
        ///// </summary>
        ///// <returns></returns>
        ////[HttpDelete]           // 参数可为空
        //[HttpDelete("{id}")] // 参数不可为空
        //[AllowAnonymous]
        //[Route("/api/[controller]/delete")]
        //public async Task<MessageModel<bool>> delete(int id)
        //{

        //    var data = new MessageModel<bool>();

        //    // 测试 AOP 缓存
        //    bool ss = await _sys_configServices.Delete(id);
        //    data.response = ss;
        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;


        //}



        ///// <summary>
        ///// 获取所有数据【无权限】
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //[AllowAnonymous]
        //[Route("/api/[controller]/GetBiaoDaShi")]
        //public async Task<MessageModel<bool>> GetBiaoDaShi(int id)
        //{

        //    var data = new MessageModel<bool>();


        //    data.msg = "获取成功！";
        //    data.success = true;
        //    return data;


        //}


        //// PUT: api/Claims/5  更新 
        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody] string value)
        //{


        //}



        //[HttpPost]
        //[Route("/api/[controller]/Post")]
        //public void Post([FromBody] string value)
        //{
        //}

        #endregion




    }
}